
local U = require "packages/hanqing/util"

local jidian = fk.CreateSkill{
  name = "hanqing__jidian",
  tags = { U.Reform },
}

Fk:loadTranslationTable{
  ["hanqing__jidian"] = "集典",
  [":hanqing__jidian"] = "<a href='hanqing_reform_skill'>变革技</a>，每轮结束时，你可以获得<a href=':handing__penal_code'>《法经》</a>"..
  "与<a href=':handing__penal_code'>《法经》</a>上的牌。",

  ["hanqing_reform_skill"] = "<b>变革技</b>：<br>"..
  "拥有“变革技”的武将拥有其专属的“律”牌，变革技可以将“律”置入指定的位置，若专属“律”均在游戏内，变革技无法发动。<br>"..
  "“律”无类型、点数、花色，以任意方式离开初始区域时，改为移出游戏。",
}

jidian:addEffect(fk.RoundEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(jidian.name) and
      player.room:getCardArea(player.room:getBanner(jidian.name)[1]) == Card.Void
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getBanner(jidian.name)
    local banner = room:getBanner("@$handing__penal_code") or {}
    if #banner > 0 then
      table.insertTable(cards, banner)
    end
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, jidian.name, nil, true, player)
    banner = table.filter(banner, function (id)
      return room:getCardArea(id) == Card.Void
    end)
    room:setBanner("@$handing__penal_code", banner)
  end,
})

jidian:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  room:addSkill("handing__penal_code_skill")
  if not room:getBanner(jidian.name) then
    local card = room:printCard("handing__penal_code")
    --card.type = 114514
    room:setBanner(jidian.name, {card.id})
  end
end)

return jidian
